package com.feeyin.radar.crm.dao.impl;

import com.feeyin.radar.commons.StringUtils;
import com.feeyin.radar.crm.dao.ContractDetailDAO;
import com.feeyin.radar.crm.model.ContractDetail;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class ContractDetailDAOImpl extends SqlMapClientDaoSupport
  implements ContractDetailDAO
{
  public BigDecimal getTotalContractGross(ContractDetail contractDetail)
  {
    return (BigDecimal)getSqlMapClientTemplate().queryForObject("getTotalContractGrossByDynamic", contractDetail);
  }

  public List getContractDetailsByContractId(Integer contractId) {
    if (contractId == null) return null;
    ContractDetail contractDetail = new ContractDetail();
    contractDetail.setContractId(contractId);
    return getSqlMapClientTemplate().queryForList("getContractDetailsByDynamic", contractDetail);
  }

  public ContractDetail getContractDetailByContractIdAndDetailCode(Integer contractId, String detailCode) {
    if (contractId == null) return null;
    if (StringUtils.isEmpty(detailCode)) return null;
    ContractDetail contractDetail = new ContractDetail();
    contractDetail.setContractId(contractId);
    contractDetail.setDetailCode(detailCode);
    return (ContractDetail)getSqlMapClientTemplate().queryForObject("getContractDetailsByDynamic", contractDetail);
  }

  public boolean insertContractDetail(ContractDetail contractDetail) {
    Integer result = (Integer)getSqlMapClientTemplate().insert("insertContractDetail", contractDetail);
    return result != null;
  }

  public boolean deleteContractDetail(Integer contractId)
  {
    Integer result = Integer.valueOf(getSqlMapClientTemplate().delete("deleteContractDetail", contractId));
    return result != null;
  }
}